
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>修改手机号</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta http-equiv="Cache-Control" content="no-transform">
		<meta name="format-detection" content="telephone=no">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<link rel="stylesheet" href="style/css/basic.css">
		<link rel="stylesheet" href="style/plugin/layui/css/layui.css" />
		<link rel="stylesheet" href="style/css/new_phone.css" />
		<script type="text/javascript" src="style/plugin/mui/js/mui.min.js"></script>
		<script type="text/javascript" src="style/js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="style/plugin/layui/layui.js"></script>
		<script type="text/javascript" src="style/mockjs/dist/mock.js"></script>
		<script type="text/javascript" src="style/js/basic.js"></script>
		
	</head>

	<body>
		<div id="header">
			<h1>修改手机号</h1>
			<span class="backicon"></span>
		</div>
		<div class="body">
			<div class="bg">
				<form>
					<div class="txt">请输入新手机号，下次登录可直接使用此号登录</div>
					<div class="tel">
						<label>新手机号</label>
						<input type="tel" placeholder="新手机号" name="tel"  class="phonenum" />
						<i class="clear_input"></i>
					</div>
					<div class="tel">
						<label>验证码</label>
						<input type="number" placeholder="验证码" name="tel"   class="sms_code" />
						<i class="clear_input clear_code"></i>
						<button class="get_code" id="getting">获取验证码</button>
						
					</div>					
				</form>
				<div class="button alterTel"><a href="javscript:void(0);">提交</a></div>
			</div>
		</div>
		<script>
			mui.plusReady(function(){
				var mask=mui.createMask()
				var ticket=localStorage.getItem("tick")
                var sign=localStorage.getItem("sig")
				$("input").each(function() {
					var vdefault = this.value;
					$(this).focus(function() {
						$(this).next().css("opacity", "1")
					});
					$(".clear_input").click(function() {
						$(this).prev().val("")
					})
					$(this).blur(function() {
			
						$(this).next().css("opacity", "0")
					})
			
				});
			
				//	获取验证码
			
				var countdown = 60;
			
				function sendemail() {
					var obj = $("#getting");
					settime(obj);
			
				}
			
				function settime(obj) { //发送验证码倒计时
					mui.ajax(domain+"/sms/changePhone?t="+ticket+"&sign="+sign,{
				    	dataType:"json",
				    	type:"post",
				    	data:{
				    		phone:$(".phonenum").val()
				    	},
				    	timeout:10000,
				    	//headers:{'Content-Type':'application/json'},
				    	success:function(data){	  
				    		if(data.code==1){
				    			mui.toast(data.msg)	
				    			countdown=60
				    			obj.attr('disabled', true);
				    			var timer=setInterval(function(){
				    			    obj.html("重新发送(" + countdown + ")");
								    countdown--;
								    if(countdown==0){
										clearInterval(timer)
										obj.attr('disabled', false);
										//obj.removeattr("disabled"); 
										obj.html("获取验证码");
										countdown = 60;
									}
				    			},1000)
				    			//console.log(countdown)
								
				    		}else if(data.code==0){
				    			mui.toast("发送失败",{duration:"short"})
				    		}
				    	},
				    	error:function(xhr,type,errorThrown){
				    		alert(type)
				    	} 
				    })
				}
				$("#getting").click(function(e) {
					e.preventDefault()
					sendemail()
				})
				//	禁止input光标
				$('input[readonly]').on('focus', function() {
					$(this).trigger('blur');
				});
				$(".alterTel").click(function(){
					var role=sessionStorage.getItem("rol")
					if($('.phonenum').val()==''){
						mui.toast("请输入你要绑定的手机号")
					}else if($(".sms_code").val()==''){
						mui.toast("请输入验证码")
					}else{
					    mui.ajax(domain+"/member/changePhone?t="+ticket+"&sign="+sign,{//提交修改手机号接口
					    	dataType:"json",
					    	type:"post",
					    	timeout:10000,
					    	//headers:{'Content-Type':'application/json'},
					    	data:{
					    		phone:$(".phonenum").val(),
					    		code:$(".sms_code").val() 
					    	},
					    	beforeSend:function(){
					    	    plus.nativeUI.showWaiting();
					    	    mask.show()	
					    	},
					    	complete:function(){
					    		plus.nativeUI.closeWaiting();
					    		mask.close()
					    	},
					    	success:function(data){	  
					    		if(data.code==1){
						    		mui.toast("修改成功")
						    		if(role==1){
						    			openurl("agent_my")
						    		}else if(role==2){
						    			openurl("sales_my")
						    		}else if(role==4){
						    			openurl("recommend_my")
						    		}else{
						    			console.log("页面不存在")
						    		}
					    		}else{
					    			mui.toast("修改失败",{duration:"short"})
					    		}
					    	},
					    	error:function(xhr,type,errorThrown){
					    		alert(type)
					    	}
					    })	
					}
				})
				mui.ajax(domain+"/member/getDetail?t="+ticket+"&sign="+sign,{//获取用户信息
			    	dataType:"json",
			    	type:"post",
			    	timeout:10000,
			    	//headers:{'Content-Type':'application/json'},
			    	success:function(data){	 
			    		console.log(data)
			    		if(data.code==1){
				    		sessionStorage.setItem("rol",data.data.role)
	
			    		}else if(data.code==0){
			    			mui.toast("数据请求失败！",{duration:"short"})
			    		}
			    	},
			    	error:function(xhr,type,errorThrown){
			    		alert(type)
			    	}
			    })
			})
		</script>
	</body>

</html>